<?php
/*
 * SoDefinedFileToCreateTableSql
 * 用于sql语句构建
 * 
 * @since 
 *      1.0 2014-9-1 by sutroon
 */
require 'Inc/incDbHead.php';
$DATABASE_SET=require 'Data/DefinedFile.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <title>SoDefinedFileToCreateTableSql</title>
        <meta charset="UTF-8">
        <style type='text/css'>
            body {font-size:12px;}
            #main { height:600px; width:780px; overflow: scroll;}
            fieldset{ margin-bottom:10px; width:960px;}
            fieldset textarea { width:100%; height:600px;}
        </style>
        <script type="text/javascript" src="/Public/Script/jquery-1.11.1.min.js"></script>
    </head>
    <body>        
        <?php
        // 显示数据库登录表单
        if (!$conn_info) {
            echoDbLoginForm();
        }
        // 全局菜单
        include 'Inc/incMenu.php';

        echo '<fieldset><legend>创建表SQL Statements:</legend><textarea>';
        foreach ($DATABASE_SET as $row) {
            $str= 'create table if not exists ' . $row['TABLE_NAME'] . ' (' . $ln;
            foreach ($row['TABLE_FIELDS'] as $row2) {
                if ($row2['Key'] == 'PRI') {
                    $str.= $tab . '`' . $row2['Field'] . '` ' . $row2['Type'] . ' ' . $row2['Extra'] . ' primary key' . ' comment \'' . $row2['Comment'] . '\',' . $ln;
                } else {
                    $str.= $tab . '`' . $row2['Field'] . '` ' . $row2['Type'] . ' ' . ($row2['Null'] == 'NO' ? 'not null' : '') . ' ' . ($row2['Default'] == '' ? '' : 'default ' . $row2['Default']) . ' ' . $row2['Extra'] . ' comment \'' . $row2['Comment'] . '\',' . $ln;
                }
            }
            $str.= ") comment '" . $row['TABLE_COMMENT'] . "' ENGINE=" . $row['ENGINE'] . " DEFAULT CHARSET=" . $row['TABLE_COLLATION'] . ";" . $ln;
            echo str_replace(",$ln) comment ", "$ln) comment ", $str);
        }
        echo '</textarea></fieldset>';

        // 释放资源
        unset($db);
        ?>
    </body>
</html>


